package com.example;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: dlernatovich
 * Date: 6/27/12
 * Time: 12:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class MyArrayAdapter extends ArrayAdapter<String> {

    private final Context context;
    private final List<String> values;

    public MyArrayAdapter(Context context, int textViewResourceId, List<String> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        this.values = objects;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.custom_list_data, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.listText);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.listIcon);
        textView.setText(values.get(position));
        String s = values.get(position);
        if (s.startsWith("Option 4") || s.startsWith("Option 3")
                || s.startsWith("Option 5")||s.startsWith("Option 6")) {
            imageView.setImageResource(android.R.drawable.ic_menu_add);
        } else {
            imageView.setImageResource(android.R.drawable.ic_menu_call);
        }

        return rowView;
    }

}
